'use strict';
	angular.module('baseinfo.fileFactorySelectSingle', [])
	.controller('fileFactorySelectSingleCtrl'
			,['$rootScope', '$scope', 'BizData', '$uibModalInstance','params', 'title'
			   , f])//控制器结束
    function f($rootScope, $scope, BizData, $uibModalInstance, params, title) {


		var Model = this;
		

		/**
		name:bizData#onBeforeDelete
		description: <b>[回调型事件]</b>业务数据删除前
		@param {object} event 它的结构如下:<br/>
		{
			"source":组件的js对象
			,"cancel":可修改	，设置为true后中断当前delete动作
			,"deleteIDList":删除的行Id数组
		}
		*/
		Model.dataListBeforeDelete = function(event) {
//			alert(event.deleteIDList[0]);
		}
		/**
		name:bizData#onAfterDelete
		description: <b>[回调型事件]</b>业务数据删除后
		@param {object} event 
		<br/><b>结构如下：</b>
		<xmp> 
		{
			"source" : 组件的js对象,
			"deleteIDList" : 删除的行Id数组
		}
		</xmp>	
		*/
		Model.dataListAfterDelete = function(event) {
//			alert('删除之后！')
		}



		
		
		/**
		name:bizData#onIndexChanged
		description: <b>[回调型事件]</b>行记录变化
		@param {object} event 
		<br/><b>结构如下：</b>
		<xmp> 
		{
			"source" : 组件的js对象,
			"rowID" : 行Id,
			"rowIndex" : 行索引
		}
		</xmp>	
		*/
		Model.dataListIndexChanged = function(event) {

		}
		
		/**
		name:bizData#onDataChanged
		description: <b>[回调型事件]</b>数据发生变化（包括新增、刷新、删除、修改引起的变化），感知从data的变化
		@param {object} event 
		<br/><b>结构如下：</b>
		<xmp> 
		{
			"source" : 组件的js对象,
			"changedSource" ：触发变化的组件的js对象，当从data触发时返回从data对象,
			"selfChanged" : 是否自身变化，false：从data触发的变化,
			"type" : 触发变化的类型，包括：new、delete、refresh、valueChanged、clear，其他参数根据触发类型不同给出不同参数，参考onAfterNew等事件参数
		}
		</xmp>	
		*/
		Model.dataListDataChanged = function(event) {
		}
		
		/**
		name:bizData#onValueChanged
		description: <b>[回调型事件]</b>数据变化
		@param {object} event 
		<br/><b>结构如下：</b>
		<xmp> 
		{
			"source" : 组件的js对象,
			"column" : 关系,
			"rowIndex" : 行索引,
			"value" : 新值,
			"originalValue" : 旧值
		}
		</xmp>	
		*/
		//输入值变化，监视input的输入，ng-change
		Model.dataListValueChanged = function(event) {

		}
		


		/**
		name:bizData#onBeforeNew
		description: <b>[回调型事件]</b>业务数据新增前
		@param {object} event 它的结构如下:<br/>{"source":组件的js对象,"cancel":可修改，设置为true后中断当前new动作}
		 */
		Model.dataListBeforeNew = function(event) {

		};
		/**
		 * name:bizData#onAfterNew description: <b>[回调型事件]</b>业务数据新增后
		 * 
		 * @param event
		 *            它的结构如下:<br/>{"source":组件的js对象,"id":新增的行Id}
		 */
		Model.dataListAfterNew = function(event){
		}


		Model.gridRowClick = function(event){
			
		}

		Model.gridRowDblClick = function(event){
			Model.ok();
		}
		
		
		var options = {};
		options.container = Model;
		options.concept = 'FileFactory';
		options.name = 'dataList';
		options.url = $rootScope.path;
		options.httpUrl = $rootScope.getServiceName();
		options.creater = '';		
		options.reader = '/baseinfo/fileFactory/list/query';
		options.writer = '/baseinfo/fileFactory/list/save';
		options.deleter = '/baseinfo/fileFactory/list/delete';
		options.idColumnDefine = "fID";
		options.idColumnName = "fID";
		options.defCols = {fID:{name:"fID",type:"String",label:""},systemCode:{name:"systemCode",type:"String",label:""},billType:{name:"billType",type:"String",label:""},billTypeName:{name:"billTypeName",type:"String",label:""},orderDate:{name:"orderDate",type:"Date",label:""},state:{name:"state",type:"String",label:""},status:{name:"status",type:"String",label:""},factoryNo:{name:"factoryNo",type:"String",label:""},factoryName:{name:"factoryName",type:"String",label:""},fAddressName:{name:"fAddressName",type:"String",label:""},fAddressDetail:{name:"fAddressDetail",type:"String",label:""},fAddress:{name:"fAddress",type:"String",label:""},fProvince:{name:"fProvince",type:"String",label:""},fCity:{name:"fCity",type:"String",label:""},fZone:{name:"fZone",type:"String",label:""},fStreet:{name:"fStreet",type:"String",label:""},fStreetNumber:{name:"fStreetNumber",type:"String",label:""},lat:{name:"lat",type:"Decimal",label:""},lng:{name:"lng",type:"Decimal",label:""},cityCode:{name:"cityCode",type:"String",label:""},contacts:{name:"contacts",type:"String",label:""},mobilePhone:{name:"mobilePhone",type:"String",label:""},fPhone:{name:"fPhone",type:"String",label:""},sMail:{name:"sMail",type:"String",label:""},faxPhone:{name:"faxPhone",type:"String",label:""},qqCode:{name:"qqCode",type:"String",label:""},postcode:{name:"postcode",type:"String",label:""},images:{name:"images",type:"String",label:""},summary:{name:"summary",type:"String",label:""},comments:{name:"comments",type:"String",label:""},cUsercode:{name:"cUsercode",type:"String",label:""},cUsername:{name:"cUsername",type:"String",label:""},cDatetime:{name:"cDatetime",type:"Datetime",label:""},tUsercode:{name:"tUsercode",type:"String",label:""},tUsername:{name:"tUsername",type:"String",label:""},tDatetime:{name:"tDatetime",type:"Datetime",label:""},eUsercode:{name:"eUsercode",type:"String",label:""},eUsername:{name:"eUsername",type:"String",label:""},eDatetime:{name:"eDatetime",type:"Datetime",label:""},sCreatorFID:{name:"sCreatorFID",type:"String",label:""},userId:{name:"userId",type:"String",label:""},enterpriseNo:{name:"enterpriseNo",type:"String",label:""},enterpriseName:{name:"enterpriseName",type:"String",label:""},iType:{name:"iType",type:"Integer",label:""},storeType:{name:"storeType",type:"String",label:""},storeTypeName:{name:"storeTypeName",type:"String",label:""},taxType:{name:"taxType",type:"Integer",label:""},taxTypeLabel:{name:"taxTypeLabel",type:"String",label:""},taxRate:{name:"taxRate",type:"Decimal",label:""},depositRate:{name:"depositRate",type:"Decimal",label:""},startTime:{name:"startTime",type:"Time",label:""},endTime:{name:"endTime",type:"Time",label:""},storageID:{name:"storageID",type:"String",label:""},storageNo:{name:"storageNo",type:"String",label:""},storageName:{name:"storageName",type:"String",label:""},floorNo:{name:"floorNo",type:"String",label:""},storageType:{name:"storageType",type:"String",label:""},storageTypeLabel:{name:"storageTypeLabel",type:"String",label:""},freeShipping:{name:"freeShipping",type:"Integer",label:""},startPrice:{name:"startPrice",type:"Decimal",label:""},renewPrice:{name:"renewPrice",type:"Decimal",label:""},startOrderAmount:{name:"startOrderAmount",type:"Decimal",label:""},freeOrderAmount:{name:"freeOrderAmount",type:"Decimal",label:""},weightsize:{name:"weightsize",type:"String",label:""},weightsizeLabel:{name:"weightsizeLabel",type:"String",label:""},version:{name:"version",type:"Integer",label:""}};
		options.isTree = false;
		options.parentRelation = 'fParent';
		options.nodeKindRelation = 'nodeKind';
		options.nodeLevelRelation = 'nodeLevel';
		options.pathRelation = 'fID';
		options.directDeleteMode = true;
		options.limit = 10;
		
		options.onIndexChanging = null;
		options.onIndexChanged = Model.dataListIndexChanged;
		options.onBeforeNew = Model.dataListBeforeNew;
		options.onAfterNew = Model.dataListAfterNew;
		options.onBeforeDelete = Model.dataListBeforeDelete;
		options.onAfterDelete = Model.dataListAfterDelete;
		options.onValueChanged = Model.dataListValueChanged;
		options.onDataChanged = Model.dataListDataChanged;
		
		Model.dataList = new BizData(options);

		//监视对象中的所有变动
		Model.dataList.deregRows = $scope.$watch('Model.dataList.rows',Model.dataList.watchRows,true);//true代表深度监视，包括对象的属性，而不是简单的一个值
		//////////////////////////////////////////////
		
		
		
		////////////////////启动执行开始///////////////////////////////////////////////////
		//接收调用的参数
//		Model.params = $rootScope.$stateParams;  
		


		////////////////////启动执行结束///////////////////////////////////////////////////
			

		
		
		//////////////////////对话框使用开始//////////////////////////////////////
		
        //模态窗口打开之后执行的事件
        $uibModalInstance.opened.then(function(){
    		//接收调用对话框的参数
            Model.title = title;  
            Model.params = params;  
    		//设置过滤条件
    		if(Model.params.billType!=undefined){
    			Model.dataList.filter = " FileFactory.billType='"+Model.params.billType+"'";
    		}

    		//刷新数据
    	    Model.dataList.refreshData();
        });  
		
        Model.ok = function () {  
	    	//保存成功
	    	//打包数据
	    	var event = {};
	    	var data = [];
	    	var sourceRow = Model.dataList.rows[Model.dataList.currentIndex];
	    	var row = {};
			//循环行中的列，判断变化点是哪一个
			for(var obj in sourceRow){
				if(obj!='$$hashKey' && obj!='userdata'){
					row[obj] = sourceRow[obj].value;
				}
			}
	    	
	    	data.push(row);
	    	event.data = data;
			$uibModalInstance.close(event);  
	    };  
	    
	    Model.cancel = function () {  
	        $uibModalInstance.dismiss('cancel');  
	    };    
		//////////////////////对话框使用结束//////////////////////////////////////
	    


		
		return Model;
	    
	    
	}	
	
